import { Button } from 'antd';
import { setToken } from '@/redux/modules/global/action';
import { connect } from 'react-redux';
import { useNavigate } from 'react-router-dom';

interface LoginProps {
  setToken: typeof setToken;
}

const Login = (props: LoginProps) => {
  const { setToken } = props;
  const navigate = useNavigate();

  // 登陆逻辑
  const handleLogin = () => {
    console.log('login');
    // 存储token
    setToken('token');
    // 跳转
    navigate('/loading');
  };

  return (
    <>
      <Button type='primary' onClick={handleLogin}>
        Login
      </Button>
    </>
  );
};

// export default Login;

// 映射dispatch到props中
const mapDispatchToProps = { setToken };
export default connect(null, mapDispatchToProps)(Login);
